#pragma once
/*!\file func.h
*/
#include "dataAboutTrees.h"
#include "tree.h"
#include "node.h"
#include "exception.h"
#include <QMap>
#include <QString>
#include <QChar>
#include <QFile>
#include <QStringList>
/*!\fn bool readFile(QString & str_tree1, QString & str_tree2, QFile & first_file, QFile & second_file)
*\brief Function to read data from files
*\param [in] <str_tree1> first file
*\param [in] <str_tree2> second file
*\param [out] <first_file> string of the first tree
*\param [out] <second_file> string of the second tree
*\return flag successful reading data
*/
bool readFile(QString & str_tree1, QString & str_tree2, QFile & first_file, QFile & second_file);
/*!\fn QString formNumber(const QString & tree, int index)
*\brief Function for forming line numbers in the string of tree
*\param [in] <tree> the string of tree
*\param [in] <index> position from which node value is formed by
*\return string value of a node
*/
QString formNumber(const QString & tree, int index);
/*!\fn QString formStrChildren (const QString & tree, int & pos)
*\brief Formation function string of children
*\param [in] <tree> the string of tree
*\param [in] <pos> position from which node-children is formed by
*\exception <exception> structure containing the error type of error and arguments indicating the location of the error
*\return string of nodes-children
*/
QString formStrChildren (const QString & tree, int & pos);
/*!\fn QVector <node*> fromStr (const QString & tree, int level, QVector <QVector <node*> > & levels, QVector <QString> & symbols)
*\brief Function to convert a string into a container tree nodes
*\param [in] <tree> the string of tree
*\param [in] <level> the current level of parent nodes
*\param [out] <levels> container tree levels with containers of sites belonging to any level
*\param [out] <symbols> container nedopustmmyh characters that contains either a repeating node or nodes invalid values
*\exception <exception> structure containing the error type of error and arguments indicating the location of the error
*\return container nodes at this level
*/
QVector <node*> fromStr (const QString & tree, int level, QVector <QVector <node*> > & levels, QVector <QString> & symbols);
/*!\fn dataAboutTrees*  preparationOfData (const QString & tree1, const QString & tree2) 
*\brief Prepare function data about trees
*\param [in] <tree1> string of the first tree
*\param [in] <tree2> string of the second tree
*\exception <exception> structure containing the error type of error and arguments indicating the location of the error
*\return data structure
*/
dataAboutTrees*  preparationOfData (const QString & tree1, const QString & tree2);
/*!\fn strToTree (const QString & str_tree)
*\brief Function to convert a string into a tree
*\param [in] <str_tree> string of the tree
*\return tree structure: pointer to its root fnd levels of the tree
*/
tree* strToTree (const QString & str_tree);
/*!\fn node* searchNode (int value, node* root)
*\brief Function for searching node in the tree
*\param [in] <value> value of the node you want to search
*\param [in] <root> pointer to the root of the tree, which searches for the node
*\return pointer to the found node, NULL if not found
*/
node* searchNode (const int value, node* root);
/*!\fn QVector < QVector <int> > createTable(const node* tree1, const node* tree2, QMap <int,int> & common_node)
*\brief Function to create a table for LCS
*\param [in] <tree1> pointer to the root of the first tree
*\param [in] <tree2> pointer to the root of the second tree
*\param [out] <common_node> map of of common nodes and descendants
*\return table in the form of containers container values
*/
QVector < QVector <int> > createTable(const node* tree1, const node* tree2, QMap <int,int> & common_node);
/*!\fn QVector <int> formValueCommonChildren (const node* root, QMap <int,int> & common_node)
*\brief Formation function values?of common nodes children of the tree
*\param [in] <root> pointer to the root of the tree
*\param [in] <common_node> map of of common nodes and descendants
*\return container values common children
*/
QVector <int> formValueCommonChildren (const node* root, QMap <int, int> & common_node);
/*!\fn void fillTable(QVector <QVector <int> > & table, QMap <int, int> & common_node)
*\brief Function to fill a table for LCS
*\param [in] <common_node> map of of common nodes and descendants
*\param [out] <table> table in the form of containers container values
*/
void fillTable(QVector <QVector <int> > & table, QMap <int, int> & common_node);
/*!\fn QVector <int> formCommonChildren(QVector <QVector <int> > & table, QMap <int, int> & common_node)
*\brief Function to analyze the table, forming a common children
*\param [in] common_node map of of common nodes and descendants
*\param [in] <table> table in the form of containers container values
*\return common container nodes children of this node
*/
QVector <int> formCommonChildren(QVector <QVector <int> > & table, QMap <int, int> & common_node);
/*!\fn QVector <node*> searchLCP (dataAboutTrees & trees)
*\brief Function to searching the largest of the common parts in trees
*\param [out] <trees> data about trees: the levels of the first and roots of trees
*\return container common nodes of the trees
*/
QVector <node*> searchLCP (dataAboutTrees & trees);
/*!\fn QVector <int> comparisonOfChildren (QMap <int,int> & common_node, const node* tree1, const node* tree2)
*\brief Function compares the two children nodes
*\param [in] <tree1> pointer to the root of the first tree
*\param [in] <tree2> pointer to the root of the second tree
*\param [out] <common_node> map of of common nodes and descendants
*\return vector of of common nodes
*/
QVector <int> comparisonOfChildren (QMap <int,int> & common_node, const node* tree1, const node* tree2);
/*!\fn void addChildren (QVector <int> & value_children, QVector <node*> & common, node* parent)
*\brief Function to join of children the specified node
*\param [in] <value_children> values of nodes-children
*\param [in] <common> map of of common nodes and descendants
*\param [in,out] <parent> node to which is coupled children
*/
void addChildren (QVector <int> & value_children, QVector <node*> & common, node* parent);
/*!\fn bool formLDP (node* root, QVector <node*> & diff)
*\brief Formation function of various parts of the tree
*\param [in] <root> pointer to the root of the tree
*\param [out] <diff> container different parts of the tree
*\return flag accessory node to the different parts
*/
bool formLDP (node* root, QVector <node*> & diff);
/*!\fn void writeFile(QVector <node*> & common, QVector <node*> & diff_tree1, QVector <node*> & diff_tree2)
*\brief Function to write result of programm in file "result.txt"
*\param [in] <common> container common parts of the trees
*\param [in] <diff_tree1> container different parts of the first tree
*\param [in] <diff_tree2> container different parts of the second tree
*/
void writeFile(QVector <node*> & common, QVector <node*> & diff_tree1, QVector <node*> & diff_tree2);
/*!\fn void writeParts(QFile & result, QVector <node*> parts)
*\brief Function to write parts
*\param [in] <parts> container parts of the trees
*\param [in] <result> file
*/
void writeParts(QFile & result, QVector <node*> parts);
/*!\fn QString toText(node* root)
*\brief Function transform tree into a string
*\param [in] <root> pointer to the root of the tree
*\return string of tree
*/
QString toText(node* root);